﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace OpenComposite.Forms
{
	public partial class FormInfoWithLink : Form
	{
		public FormInfoWithLink()
		{
			InitializeComponent();

			this.pictureBox1.Image = SystemIcons.Information.ToBitmap();
		}

		public string LinkTitle
		{
			get { return lnkMore.Text; }
			set { lnkMore.Text = value; }
		}

		private string _link = null;
		public string Link
		{
			get { return _link; }
			set { _link = value; }
		}

		private const int minMessageHeight = 60;
		public string Message
		{
			get { return lblInfo.Text; }
			set
			{
				lblInfo.Text = value;
				Graphics g = Graphics.FromHwnd(this.Handle);
				if ( g != null ) {
					SizeF size = g.MeasureString(lblInfo.Text, lblInfo.Font, lblInfo.Width);
					int newHeight = Math.Max(60, (int)size.Height);
					tableLayoutPanel1.RowStyles[0].Height = newHeight;
				}
			}
		}

		private void lnkMore_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			if ( string.IsNullOrEmpty(_link) ) return;
			Process.Start(_link);
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}

	public static class InfoBox
	{
		public static void Show(string message, string title, string linkLabel, string link)
		{
			using ( FormInfoWithLink info = new FormInfoWithLink() ) {
				info.Message = message;
				info.Text = title;
				info.LinkTitle = linkLabel;
				info.Link = link;
				info.ShowDialog();
			}
		}
	}

}
